<?php
/**
 * Created by JetBrains PhpStorm.
 * User: scala
 * Date: 12-10-25
 * Time: 上午10:03
 * To change this template use File | Settings | File Templates.
 */
class EMarketingAction extends CommonAction
{

    function index(){
        $em=M("Emarketing");
        import("ORG.Util.Page");// 导入分页类
        $count=$em->count();
        $Page= new Page($count,10);// 实例化分页类 传入总记录数和每页显示的记录数
        $Page->setConfigArray(array('header'=>'条营销','prev'=>'<input type="button" value="<<<">','next'=>'<input type="button" value=">>>">','first'=>'首页','last'=>'尾页','theme'=>' %totalRow% %header% %nowPage%/%totalPage% 页   %first% %prePage% %upPage%   <span style="color: red;background-color: #7fffd4;">%linkPage%</span>   %downPage% %nextPage% %end%'));
        $show=$Page->show();//分页显示输出
        $list=$em->order("createtime desc")->limit($Page->firstRow.",".$Page->listRows)->select();
        $this->assign("list",$list);
        $this->assign('page',$show);// 赋值分页输出
        $this->display();
    }


    function add(){
        $this->display();
    }


    function insert(){
        $em=D("Emarketing");
        if($em->create()){
            if($result=$em->add()){
                $this->sitemapWriter("EMarketing/details","EMarketing",$result);
                $this->redirect("index");
            }else{
                $this->error("添加失败".$em->getError());
            }
        }else{
            $this->error("添加信息失败!".$em->getError());
        }
    }


    function  delete(){
        $em=M("Emarketing");
        if(!empty($_GET["id"])){
            $em->delete($_GET["id"]);
            $this->sitemapDeleter("EMarketing",$_GET['id']);
        }
        $this->redirect("index");
    }


    function  view(){
        $em=M("Emarketing");
        if(!empty($_GET["id"])){
            $list= $em->find($_GET["id"]);
            $this->assign("list",$list);
        }
        $this->display();
    }


    function update(){
        $em=D("Emarketing");
        if($em->create()){
            $em->save();
        }
        $this->redirect("index");
    }

}
